<style>
    .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
        border: 1px solid #989898;
    }
    .table-bordered {
        border: 1px solid #989898;
    }
</style>
<form id="add-form" class="form-horizontal" method="POST" action="{:url('hsave')}">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">应用行业名称:</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" name="name" value="{$data['name']|default=''}" class="form-control"/>
        </div>
    </div>
     <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">应用行业描述:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea type="text" name="des" id="des" class="form-control">{$data['des']|default=''}</textarea>
        </div>
     </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">板块类型:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="fixed-table-body">
                <table id="table" class="table table-striped table-bordered table-hover" width="100%" style="background-color: #fff;">
                    <thead>
                        <tr>
                            <th style="text-align: center; vertical-align: middle; ">
                                <div class="th-inner ">板块</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; ">
                                <div class="th-inner ">子板块</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; ">
                                <div class="th-inner ">前后台</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; ">
                                <div class="th-inner ">页面</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; ">
                                <div class="th-inner ">功能</div>
                                <div class="fht-cell"></div>
                            </th>
                        </tr>
                    </thead>
                    <tbody data-listidx="0">
                       {volist name="plate" id="vo" key="k"}
                         {if condition="!empty($vo['child'])"}
                            {volist name="vo['child']" id="ch" key="ck"}
                              {php}

                                if($ch=="无"){
                                     $home=db('page')->where(['admin_home'=>1,'plate_id'=>$vo['id']])->select();

                                     $admin=db('page')->where(['admin_home'=>2,'plate_id'=>$vo['id']])->select();
                                }else{
                                      $home=db('page')->where(['admin_home'=>1,'plate_id'=>$ch['id']])->select();

                                      $admin=db('page')->where(['admin_home'=>2,'plate_id'=>$ch['id']])->select();
                                }

                                 $home_count=count($home);
                                 $admin_count=count($admin);

                                 $child_count=$home_count+$admin_count;
                              {/php}


                           {volist name="home" id="page" key="pk"}
                              <tr>
                                {if condition="$ck eq 1 AND $pk eq 1"}
                                   <td style="text-align: center; vertical-align: middle;" rowspan="{$vo['page_count']}"><!-- 总行数(页面数) -->
                                      <label style="font-weight: normal;"><input type="checkbox" name="bid[]"  value="{$vo.id}" data-bid="{$vo.id}" {if condition="(!empty($data)) AND in_array($vo['id'],$data['bid'])"}checked{/if}>{$vo.name}</label>
                                   </td>
                                 {/if}
                                {if condition="$pk eq 1"}
                                  <td style="text-align: center; vertical-align: middle;"  rowspan="{$child_count}">
                                      <label style="font-weight: normal;">
                                       {if condition="$ch eq '无'"}
                                          无
                                       {else/}
                                        <input type="checkbox" name="child_bid[]" class="checkbox_{$vo.id}" value="{$ch.id}"
                                        {if condition="(!empty($data)) AND in_array($ch['id'],$data['child_bid'])"}checked{/if}>{$ch.name}
                                       {/if}
                                    </label>
                                  </td>
                                {/if}
                                  <td style="text-align: center; vertical-align: middle;">
                                      前台页面
                                  </td>
                                <td style="text-align: center; vertical-align: middle;">
                                    <label style="font-weight: normal;"><input type="checkbox" name="page_id[]" {if condition="$ch neq '无'"} data-child_plate="{$ch['id']}" {/if} class="checkbox_{$vo.id}" value="{$page.id}" {if condition="(!empty($data)) AND in_array($page['id'],$data['page_id'])"}checked{/if} >{$page['name']}</label>
                                </td>
                                <td style="text-align: center; vertical-align: middle;">
                                  {php}
                                      $gongnen=db('plate_gongnen')->where(['page_id'=>$page['id']])->select();
                                    {/php}
                                   {volist name="gongnen" id="g"} 
                                     {php}
                                        $info=db('gongnen')->where('id', $g['gid'])->find();
                                        $data_ch=db('gongnen_child')->where('id', $g['child_id'])->find();
                                     {/php}
                                    <label style="font-weight: normal;"><input type="checkbox" name="gong_id[]" {if condition="$ch neq '无'"} data-child_plate="{$ch['id']}" {/if} class="checkbox_{$vo.id}" value="{$g.id}" {if condition="(!empty($data)) AND in_array($g['id'],$data['gong_id'])"}checked{/if} >{$info.name}-{$data_ch['cname']}</label>
                                   {/volist} 
                                </td>
                            </tr>
                           {/volist}

                          {volist name="admin" id="page" key="pk"}
                            <tr>
                                {if condition="$home eq '' AND $ck eq 1 AND $pk eq 1"}
                                   <td style="text-align: center; vertical-align: middle;" rowspan="{$vo['page_count']}"><!-- 总行数(页面数) -->
                                      <label style="font-weight: normal;"><input type="checkbox" name="bid[]" value="{$vo.id}" data-bid="{$vo.id}" {if condition="(!empty($data)) AND in_array($vo['id'],$data['bid'])"}checked{/if}>{$vo.name}</label>
                                   </td>
                                {/if}
                                {if condition="$pk eq 1"}
                                   <td style="text-align: center; vertical-align: middle;"  rowspan="{$child_count}">
                                      <label style="font-weight: normal;">
                                        {if condition="$ch eq '无'"}
                                          无
                                        {else/}
                                          <input type="checkbox" name="child_bid[]" class="checkbox_{$vo.id}" value="{$ch.id}"
                                                 {if condition="(!empty($data)) AND in_array($ch['id'],$data['child_bid'])"}checked{/if}>{if condition="$pk eq 1"}{$ch.name}{/if}
                                        {/if}
                                    </label>
                                  </td>
                                {/if}
                                  <td style="text-align: center; vertical-align: middle;">
                                      后端页面
                                  </td>
                                <td style="text-align: center; vertical-align: middle;">
                                    <label style="font-weight: normal;"><input type="checkbox" name="page_id[]" {if condition="$ch neq '无'"} data-child_plate="{$ch['id']}" {/if} class="checkbox_{$vo.id}" value="{$page.id}" {if condition="(!empty($data)) AND in_array($page['id'],$data['page_id'])"}checked{/if}>{$page['name']}</label>
                                </td>
                                <td style="text-align: center; vertical-align: middle;">
                                  {php}
                                      $gongnen=db('plate_gongnen')->where(['page_id'=>$page['id']])->select();
                                    {/php}
                                   {volist name="gongnen" id="g"} 
                                     {php}
                                        $info=db('gongnen')->where('id', $g['gid'])->find();
                                        $data_ch=db('gongnen_child')->where('id', $g['child_id'])->find();
                                     {/php}
                                    <label style="font-weight: normal;"><input type="checkbox" class="checkbox_{$vo.id}" name="gong_id[]" {if condition="$ch neq '无'"} data-child_plate="{$ch['id']}" {/if} value="{$g.id}" {if condition="(!empty($data)) AND in_array($g['id'],$data['gong_id'])"}checked{/if} >{$info.name}-{$data_ch['cname']}</label>
                                   {/volist} 
                                </td>
                            </tr>
                          {/volist}

                        {/volist}
                        <!-- 一列 -->
                      {else /}
                          {php}

                             $home=db('page')->where(['admin_home'=>1,'plate_id'=>$vo['id']])->select();

                             $admin=db('page')->where(['admin_home'=>2,'plate_id'=>$vo['id']])->select();

                             $home_count=count($home);
                             $admin_count=count($admin);


                          {/php}
                       {volist name="$home" id="page" key="pk"}
                        <tr>
                           {if condition="$pk eq 1"}
                            <td style="text-align: center; vertical-align: middle;" rowspan="{$vo['page_count']}"><!-- 总行数(页面数) -->

                               <label style="font-weight: normal;"><input type="checkbox" name="bid[]" value="{$vo.id}" data-bid="{$vo.id}" {if condition="(!empty($data)) AND in_array($vo['id'],$data['bid'])"}checked{/if}>{$vo.name}</label>

                            </td>
                            <td style="text-align: center; vertical-align: middle;" rowspan="{$home_count}">
                                <label style="font-weight: normal;">
                                    无
                                </label>
                            </td>
                           {/if}
                           <td style="text-align: center; vertical-align: middle;">
                               前台页面
                           </td>
                           <td style="text-align: center; vertical-align: middle;">
                               <label style="font-weight: normal;"><input type="checkbox" name="page_id[]" data-child_plate="" class="checkbox_{$vo.id}" value="{$page.id}" {if condition="(!empty($data)) AND in_array($page['id'],$data['page_id'])"}checked{/if} >{$page['name']}</label>
                           </td>
                           <td style="text-align: center; vertical-align: middle;">
                               {php}
                               $gongnen=db('plate_gongnen')->where(['page_id'=>$page['id']])->select();
                               {/php}
                               {volist name="gongnen" id="g"}
                               {php}
                               $info=db('gongnen')->where('id', $g['gid'])->find();
                               $data_ch=db('gongnen_child')->where('id', $g['child_id'])->find();
                               {/php}
                               <label style="font-weight: normal;"><input type="checkbox" name="gong_id[]" data-child_plate="" class="checkbox_{$vo.id}" value="{$g.id}" {if condition="(!empty($data)) AND in_array($g['id'],$data['gong_id'])"}checked{/if} >{$info.name}-{$data_ch['cname']}</label>
                               {/volist}
                           </td>
                       </tr>
                       {/volist}

                       {volist name="$admin" id="page" key="pk"}
                       <tr>
                          {if condition="$home eq '' AND $pk eq 1"}
                           <td style="text-align: center; vertical-align: middle;" rowspan="{$vo['page_count']}"><!-- 总行数(页面数) -->

                               <label style="font-weight: normal;"><input type="checkbox" name="bid[]" value="{$vo.id}" data-bid="{$vo.id}" {if condition="(!empty($data)) AND in_array($vo['id'],$data['bid'])"}checked{/if}>{$vo.name}</label>

                           </td>
                          {/if}
                          {if condition="$pk eq 1"}
                           <td style="text-align: center; vertical-align: middle;" rowspan="{$admin_count}">
                               <label style="font-weight: normal;">
                                   无
                               </label>
                           </td>
                          {/if}
                           <td style="text-align: center; vertical-align: middle;">

                               后端页面

                           </td>
                           <td style="text-align: center; vertical-align: middle;">
                               <label style="font-weight: normal;"><input type="checkbox" name="page_id[]" data-child_plate="" class="checkbox_{$vo.id}" value="{$page.id}" {if condition="(!empty($data)) AND in_array($page['id'],$data['page_id'])"}checked{/if} >{$page['name']}</label>
                           </td>
                           <td style="text-align: center; vertical-align: middle;">
                               {php}
                               $gongnen=db('plate_gongnen')->where(['page_id'=>$page['id']])->select();
                               {/php}
                               {volist name="gongnen" id="g"}
                                 {php}
                                  $info=db('gongnen')->where('id', $g['gid'])->find();
                                  $data_ch=db('gongnen_child')->where('id', $g['child_id'])->find();
                                 {/php}
                               <label style="font-weight: normal;"><input type="checkbox" name="gong_id[]" data-child_plate="" class="checkbox_{$vo.id}" value="{$g.id}" {if condition="(!empty($data)) AND in_array($g['id'],$data['gong_id'])"}checked{/if} >{$info.name}-{$data_ch['cname']}</label>
                               {/volist}
                           </td>
                       </tr>
                       {/volist}
                      {/if}
                    {/volist}


              
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">应用逻辑:</label>
        <div class="col-xs-12 col-sm-8">
            <table class="table table-striped table-bordered table-hover">
              <tr> <th>类目</th> <th>工时</th> <th>说明</th></tr>

             {volist name="logic" id="vo"}  
              <tr> <td><input type="radio" name="logic_id" {if condition="(!empty($data)) AND $data['logic_id'] == $vo['id']"}checked{/if} value="{$vo.id}">{$vo.name}</td> <td>{$vo.cycle}</td> <td>{$vo.des}</td></tr>
             {/volist}  
          </table>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <input type="hidden" name="id" value="{$data['id']|default=''}" class="form-control"/>
            <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
        </div>
    </div>
</form>


<script>
    $(function(){
       $("input[name='bid[]']").click(function(){
           var id=$(this).val();

           var checked=$(this).prop("checked");
           $(".checkbox_"+id).each(function(){
              $(this).prop("checked",checked);
          });
        
       });

        $("input[name='page_id[]']").click(function(){
           
           var gongnen_check=$(this).parents("td").next('td').find("input[name='gong_id[]']");
           var className=$(this).attr('class');
           var bid=className.split('_');
           var bid=bid[1];
           var bankuai_check=$("input[data-bid="+bid+"]");

           var checked=$(this).prop("checked");
           gongnen_check.each(function(){
                $(this).prop("checked",checked);
            });
            bankuai_check.each(function(){
                var that=$(this);
                if(checked){
                    $(this).prop("checked",checked);
                }else{
                    $(".checkbox_"+bid).each(function(){
                        if($(this).prop("checked")){
                            that.prop("checked",true);
                            return false;
                        }else{
                            that.prop("checked",checked);
                        }
                    });
                }
            });
        
       });

      $("input[name='child_bid[]']").click(function(){
           
           var child_id=$(this).val();
           var checked=$(this).prop("checked");

           $("input[data-child_plate="+child_id+"]").each(function(){
              $(this).prop("checked",checked);
           });
           
        
       });

    })
</script>